package com.graduation.rescuematerial.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.rescuematerial.mapper.UserActionMapper;
import com.graduation.rescuematerial.pojo.UserAction;
import com.graduation.rescuematerial.service.IUserActionService;
import com.graduation.rescuematerial.vo.RespBean;
import com.graduation.rescuematerial.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CaiShuangLian
 * @since 2022-04-27
 */
@Service
public class UserActionServiceImpl extends ServiceImpl<UserActionMapper, UserAction> implements IUserActionService {

    @Autowired
    private UserActionMapper userActionMapper;


    @Override
    public RespBean updateUserAction(String companyName, Long phone, String action) {

        //校验权限是否合法
        if(!action.equals("organization_administrator")&&!action.equals("organization_member")){
            return RespBean.error(RespBeanEnum.BIN_ERROR,"无该权限，请查看权限名是否输入正确");
        }

        //系统用户直接修改
        if(companyName.equals("系统管理员组织（root）")){
            if(userActionMapper.updateUserAction(phone,action)<1){
                return RespBean.error(RespBeanEnum.UPDATE_ERROR,"修改失败");
            }
            return RespBean.success("修改成功");
        }

        //组织管理员只能修改本部门成员权限
        if(userActionMapper.updateOrgUserAction(companyName,phone,action)<1){
            return RespBean.error(RespBeanEnum.UPDATE_ERROR,"修改失败，只能修改本部门成员");
        }
        return RespBean.success("修改成功");
    }
}
